package com.example.spring.framework.aop.aspect;

import com.example.spring.framework.aop.intercept.MethodInterceptor;
import com.example.spring.framework.aop.intercept.MethodInvocation;

import java.lang.reflect.Method;

/**
 * @Classname MethodBeforeAdviceInterceptor
 * @Date 2019/4/23 0:08
 * @Author admin
 * @Description TODO
 */
public class MethodBeforeJAdviceInterceptor extends AbstractAspectJAdvice implements Advice, MethodInterceptor {

    private JoinPoint joinPoint;

    public MethodBeforeJAdviceInterceptor(Method aspectMethod, Object aspectObject) {
        super(aspectMethod, aspectObject);
    }

    @Override
    public Object invoke(MethodInvocation invocation) throws Throwable {
        this.joinPoint = invocation;
        before(invocation.getMethod(), invocation.getArguments(), invocation.getThis());
        return invocation.procccd();
    }

    private void before(Method method, Object[] args, Object target) throws Throwable {
        super.invokeAdviceMethod(this.joinPoint, null, null);
    }
}
